Completed
Push — master ( 7588c2...f404fc )
by Maxence
03:40
created

resultMembers.removeMemberResult   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 19
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var resultMembers = {
38
39
40
	searchMembersResult: function (response) {
41
42
		elements.membersSearchResult.children().remove();
43
44
		if (response === null) {
45
			elements.membersSearchResult.fadeOut(0);
46
			return;
47
		}
48
49
		elements.fillMembersSearch('users', response.ocs.data.exact.users, response.ocs.data.users);
50
		elements.fillMembersSearch('groups', response.ocs.data.exact.groups,
51
			response.ocs.data.groups);
52
53
		if (elements.membersSearchResult.children().length === 0) {
54
			elements.membersSearchResult.fadeOut(0);
55
			return;
56
		}
57
58
		$('.members_search').on('click', function () {
59
			curr.searchUserSelected = $(this).attr('searchresult');
60
			if ($(this).attr('source') === 'groups') {
61
62
				OC.dialogs.confirm(
63
					t('circles',
64
						'This operation will add/invite all members of the group to the circle'),
65
					t('circles', 'Please confirm'),
66
					function (e) {
67
						if (e === true) {
68
							api.addGroupMembers(curr.circle, curr.searchUserSelected,
69
								resultMembers.addGroupMembersResult);
70
						}
71
					});
72
			} else {
73
				api.addMember(curr.circle, curr.searchUserSelected,
74
					resultMembers.addMemberResult);
75
			}
76
		});
77
		elements.membersSearchResult.fadeIn(300);
78
	},
79
80
81
	addMemberResult: function (result) {
82
83
		if (curr.circleDetails.type === define.typeClosed) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
84
			resultMembers.inviteMemberResult(result);
85
			return;
86
		}
87
88
		if (result.status === 1) {
89
			OCA.notification.onSuccess(
90
				t('circles', "The member '{name}' was added to the circle",
91
					{name: result.name}));
92
93
			nav.displayMembers(result.members);
94
			return;
95
		}
96
		OCA.notification.onFail(
97
			t('circles', "The member '{name}' could not be added to the circle",
98
				{name: result.name}) +
99
			': ' + ((result.error) ? result.error : t('circles', 'no error message')));
100
	},
101
102
103
	addEmailResult: function (result) {
104
105
		if (result.status === 1) {
106
			OCA.notification.onSuccess(
107
				t('circles', "The email address '{email}' was added to the circle",
108
					{email: result.email}));
109
110
			nav.displayMembers(result.members);
111
			return;
112
		}
113
		OCA.notification.onFail(
114
			t('circles', "The email address '{email}' could not be added to the circle",
115
				{email: result.email}) +
116
			': ' + ((result.error) ? result.error : t('circles', 'no error message')));
117
	},
118
119
120
	inviteMemberResult: function (result) {
121
122
		if (result.status === 1) {
123
			OCA.notification.onSuccess(
124
				t('circles', "The member '{name}' was invited to the circle",
125
					{name: result.name}));
126
127
			nav.displayMembers(result.members);
128
			return;
129
		}
130
		OCA.notification.onFail(
131
			t('circles', "The member '{name}' could not be invited to the circle",
132
				{name: result.name}) +
133
			': ' + ((result.error) ? result.error : t('circles', 'no error message')));
134
	},
135
136
137
	addGroupMembersResult: function (result) {
138
139
		if (curr.circleDetails.type === define.typeClosed) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
140
			resultMembers.inviteGroupMembersResult(result);
141
			return;
142
		}
143
144
		if (result.status === 1) {
145
			OCA.notification.onSuccess(
146
				t('circles', "Members of the group '{name}' were added to the circle",
147
					{name: result.name}));
148
149
			nav.displayMembers(result.members);
150
			return;
151
		}
152
		OCA.notification.onFail(
153
			t('circles', "Members of the group '{name}' could not be added to the circle",
154
				{name: result.name}) +
155
			': ' +
156
			((result.error) ? result.error : t('circles', 'no error message')));
157
	},
158
159
160
	inviteGroupMembersResult: function (result) {
161
162
		if (result.status === 1) {
163
			OCA.notification.onSuccess(
164
				t('circles', "Members of the group '{name}' were invited to the circle",
165
					{name: result.name}));
166
167
			nav.displayMembers(result.members);
168
			return;
169
		}
170
		OCA.notification.onFail(
171
			t('circles', "Members of the group '{name}' could not be invited to the circle",
172
				{name: result.name}) +
173
			': ' +
174
			((result.error) ? result.error : t('circles', 'no error message')));
175
	},
176
177
178
	removeMemberResult: function (result) {
179
		if (result.status === 1) {
180
181
			elements.mainUIMembersTable.children("[member-id='" + result.user_id + "']").each(
182
				function () {
183
					$(this).hide(300);
184
				});
185
			OCA.notification.onSuccess(
186
				t('circles', "The member '{name}' was removed from the circle",
187
					{name: result.name}));
188
			return;
189
		}
190
191
		OCA.notification.onFail(
192
			t('circles', "The member '{name}' could not be removed from the circle",
193
				{name: result.name}) +
194
			': ' +
195
			((result.error) ? result.error : t('circles', 'no error message')));
196
	},
197
198
	levelMemberResult: function (result) {
199
		if (result.status === 1) {
200
			OCA.notification.onSuccess(
201
				t('circles', "Member '{name}' updated",
202
					{name: result.name}));
203
204
			nav.displayMembers(result.members);
205
			return;
206
		}
207
208
		nav.displayMembers('');
209
		OCA.notification.onFail(
210
			t('circles', "The member '{name}' could not be updated", {name: result.name}) +
211
			': ' +
212
			((result.error) ? result.error : t('circles', 'no error message')));
213
	}
214
215
};
216